package com.example.securityproject.demos.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.securityproject.demos.dao.TUserDao;
import com.example.securityproject.demos.entity.TUser;
import com.example.securityproject.demos.service.TUserService;
import com.example.securityproject.demos.vo.MenuVO;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (TUser)表服务实现类
 *
 * @author Jiangjb
 * @since 2024-04-09 16:38:47
 */
@Service
public class TUserServiceImpl extends ServiceImpl<TUserDao, TUser> implements TUserService {

    @Override
    public TUser getUserInfoByUsername(String userName) {
        LambdaQueryWrapper<TUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper
                .select(TUser::getUsername, TUser::getPassword)
                .eq(TUser::getUsername, userName)
                .last("LIMIT 1");
        return this.baseMapper.selectOne(queryWrapper);
    }

    @Override
    public List<MenuVO> queryMenus(String userName) {
        return this.baseMapper.queryMenus(userName);
    }

    @Override
    public TUser loadUserByUsername(String username) {
        LambdaQueryWrapper<TUser> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper
                .select(TUser::getId, TUser::getUsername, TUser::getPassword)
                .eq(TUser::getUsername, username)
                .last("LIMIT 1");
        return this.baseMapper.selectOne(queryWrapper);
    }
}
